package cn.itcast.com.homework.day723;
/*
 a.  定义一个接口Compute，用来完成计算器的功能，比如最简单的加减乘除功能
  interface Compute {
double compute(double a, double b)
  }
 b. 定义一个ShowCompute类，里面定义一个工具方法compute(Compute com,double a, double b)
    该方法可以执行，两个double类型数据的加减乘除
   （也就是需要定义不同的Compute接口的子类，实现具体的加减乘除功能，当执行该方法时，
     传递不同的子类对象，就可以完成不同的计算）
    编写一个测试类，
通过调用ShowCompute类的compute(Compute com,double a, double b)
方法来完成加减乘除功能

add , subtract , multiply and divide
 */

public class test1 {

    public static void main(String[] args) {
        Add add = new Add();
        Subtract subtract = new Subtract();
        Multiply multiply = new Multiply();
        Devide devide = new Devide();
        double a = 1;
        double b = 2;
        ShowCompute showCompute = new ShowCompute();
        System.out.println(a+"+"+b+"="+showCompute.compute(add,a,b));
        System.out.println(a+"-"+b+"="+showCompute.compute(subtract,a,b));
        System.out.println(a+"*"+b+"="+showCompute.compute(multiply,a,b));
        System.out.println(a+"/"+b+"="+showCompute.compute(devide,a,b));

    }

}
interface Compute{
    double compute(double a, double b);
}

class Add implements Compute {

    @Override
    public double compute(double a, double b) {
        return a + b;
    }
}

class Subtract implements Compute{

    @Override
    public double compute(double a, double b) {
        return a - b;
    }
}

class Multiply implements Compute{

    @Override
    public double compute(double a, double b) {
        return a * b;
    }
}

class Devide implements Compute{

    @Override
    public double compute(double a, double b) {
        return a / b;
    }
}

class ShowCompute{
    public double compute(Compute com, double a, double b){
        return com.compute(a,b);
    }
}